/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cliente;

import view.Cliente.JanelaChat;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author douglas
 */
public class ThreadAtualizaLista extends Thread{
    
    private DatagramSocket socket;
    private DatagramPacket pacote;
    private String lista;
    
    public ThreadAtualizaLista(){
        
        try {
            socket = new DatagramSocket(44444);
        } catch (SocketException ex) {
            Logger.getLogger(ThreadAtualizaLista.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    @Override
    public void run() {
        while(true){
        byte [] lista_online = new byte[1024];
        
            pacote = new DatagramPacket(lista_online, lista_online.length);
            try {
                socket.receive(pacote);
            } catch (IOException ex) {
                Logger.getLogger(ThreadAtualizaLista.class.getName()).log(Level.SEVERE, null, ex);
            }
         lista = new String(pacote.getData());
            //System.out.println(lista.split(":")[0]);
            if(!lista.split(":")[0].equals("0"))
            JanelaChat.getChat().AtualizaLista(lista);
    }
    }
    
}
